//
//  TerminalVC.m
//  CJRailTransport
//
//  Created by Hank on 2018/1/26.
//  Copyright © 2018年 amplity. All rights reserved.
//
// 顶层按钮的宽度
#define TopBtnWidth    80
// 顶层按钮的高度
#define TopBtnHeight    40
// 顶层按钮的间隙
#define TopBtnSpacing  50

#import "TerminalVC.h"
#import "TerminalListVC.h"

@interface TerminalVC ()<TYTabPagerControllerDataSource, TYTabPagerControllerDelegate>
// 栏目数组
@property (nonatomic, strong) NSArray *columnArray;

@end

@implementation TerminalVC

#pragma mark - lifeCycle
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // 加载栏目样式
        [self configurePagerStyles];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        // 加载栏目样式
        [self configurePagerStyles];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 加载栏目按钮样式
    [self configureTabButtonPager];
    // 加载数据
    [self loadData];
    // 设置导航栏
    [self setNavC];
    // 设置界面属性
    [self setViewAttribute];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    // 更改顶端滑动视图的位置
    self.tabBar.frame = CGRectMake((self.view.yj_width - TopBtnWidth * self.columnArray.count - TopBtnSpacing * (self.columnArray.count - 1)) / 2, kNavBarHeight + 8 / 2, TopBtnWidth * self.columnArray.count + TopBtnSpacing * (self.columnArray.count - 1) + 1, TopBtnHeight - 8);
}

// 加载栏目样式
- (void)configurePagerStyles
{
    self.tabBarHeight = TopBtnHeight;
}

// 加载栏目按钮样式
- (void)configureTabButtonPager
{
    self.dataSource = self;
    self.delegate = self;
    self.tabBar.layout.barStyle = TYPagerBarStyleCoverView;
    self.tabBar.layout.progressColor = [UIColor whiteColor];
    self.tabBar.layout.progressBorderWidth = 0.5;
    self.tabBar.layout.progressBorderColor = HEXCOLOR(kColorOrange4, 1);
    self.tabBar.layout.normalTextColor = [UIColor darkGrayColor];
    self.tabBar.layout.selectedTextColor = HEXCOLOR(kColorOrange4, 1);
    self.tabBar.layout.normalTextFont = [UIFont systemFontOfSize:14];
    self.tabBar.layout.selectedTextFont = [UIFont systemFontOfSize:15];
    self.tabBar.layout.cellWidth = TopBtnWidth;
    self.tabBar.layout.cellSpacing = TopBtnSpacing;
    self.tabBar.layout.cellEdging = 0;
    self.tabBar.layout.adjustContentCellsCenter = YES;
}

#pragma mark - 导航栏
- (void)setNavC
{
    self.title = @"场站";
    // 设置导航栏颜色
    BasicNavigationController *nVC = (BasicNavigationController *)self.navigationController;
    nVC.themeColor = [UIColor whiteColor];
    nVC.tintColor = [UIColor darkGrayColor];
}

// 设置界面属性
- (void)setViewAttribute
{
    self.view.backgroundColor = [UIColor whiteColor];
}

#pragma mark - load data
// 加载数据
- (void)loadData
{
    self.columnArray = @[@"入场编码",@"出场编码"];
    // 刷新数据
    [self reloadData];
}

#pragma mark - TYTabPagerControllerDataSource

- (NSInteger)numberOfControllersInTabPagerController {
    return _columnArray.count;
}

- (UIViewController *)tabPagerController:(TYTabPagerController *)tabPagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
    TerminalListVC *terminalListVC = [[TerminalListVC alloc]init];
    terminalListVC.index = index;
    return terminalListVC;
}

- (NSString *)tabPagerController:(TYTabPagerController *)tabPagerController titleForIndex:(NSInteger)index {
    NSString *title = _columnArray[index];
    return title;
}

- (void)dealloc
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
